﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace RouteEventDemo01
{
    /// <summary>
    /// AttachEventWindow.xaml 的交互逻辑
    /// 这个例子是 附加事件  
    /// </summary>
    public partial class AttachEventWindow : Window
    {
        public AttachEventWindow()
        {
            InitializeComponent();
            //StackPanel1.AddHandler(Button.ClickEvent, new RoutedEventHandler(Button_Click));
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //其中 sender是stackpanel对象
            //e.Source 是触发事件的对象
            Button btn = e.Source as Button;
            if (btn.Name == "Button1")
            {
                Console.WriteLine("Button Clicked 1");

            }
            else if (btn.Name == "Button2")
            {
                Console.WriteLine("Button Clicked 2");

            }
            else if (btn.Name == "Button3")
            {
                Console.WriteLine("Button Clicked 3");

            }
        }
    }
}
